//
//  NewTaskVC.m
//  ZhiBoYuan
//
//  Created by apple on 2018/4/19.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "NewTaskVC.h"

#import "NewTaskCell.h"

#import "YJSelectionView.h"

#import "WTTableAlertView.h"

#import "WSDatePickerView.h"
#import "SelectedBanJIVC.h"

#define MaxTextLength 50

static NSString *ident = @"NewTaskCell";

@interface NewTaskVC ()
<
UITextFieldDelegate
,UICollectionViewDelegate
,UICollectionViewDataSource
,UITextViewDelegate
>

@property (nonatomic,strong)UITextField *afield;
@property (nonatomic,strong)UITextField *bfield;
@property (nonatomic,strong)UITextField *cfield;
@property (nonatomic,strong)UITextField *dfield;

@property (nonatomic,strong)UITextView *textView;


@property (nonatomic,strong)UIButton *button;

/*  班级总数据  */
@property (nonatomic,strong)NSMutableArray *banJiArr;

@property (nonatomic,strong)UICollectionView *collectionView;



/*  班级选择后的数据  */

@property (nonatomic,strong)NSMutableArray *seletedbanJiArr;
@property (nonatomic,assign)BOOL isFree;


@property (nonatomic,strong)UILabel *backLabel;

@property (nonatomic,strong) UITapGestureRecognizer *tap;


@property(nonatomic,strong)NSArray *buttons;


@property(nonatomic,strong)NSMutableArray *allArr;



@end

@implementation NewTaskVC


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"新建任务";
    
    [self layoutUI];
    
    self.isFree = NO;
    
    
}


- (void)setTask:(Task *)task{
    _task = task;
    
}

#pragma mark ----------------------- 获取班级全部数据 -----------------------
-(void)getData {
    
    SGParameter *parameter  = [[SGParameter alloc] init];
    
    
    NSString *lastUrl  = @"g=Client&m=Class&a=myClass";
    
    [SGHttpTool POST:[NSString stringWithFormat:@"%@%@",HTTPP,lastUrl] parameter:parameter sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject;
        NNSLog(@"111 = %@",dic);
        self.allArr = dic[@"data"][@"class_list"];
        //
        NNSLog(@"22 = %@", self.allArr);
        
        [self yeMianFuzhi];
        
        [self.collectionView reloadData];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        
    }];
    
}

#pragma mark ----------------------- 编辑页面赋值 ------------------------
-(void)yeMianFuzhi{
    if (_task) {
        
        _afield.text = _task.name;
        
        _textView.text = _task.detail;
        _textView.textColor = [UIColor blackColor];
        
        _dfield.text = _task.work_time;
        
        if ([_task.is_free integerValue] == 0) {
            [_buttons[0] setSelected:YES];
            self.isFree = NO;
        }else{
            [_buttons[1] setSelected:YES];
            self.isFree = YES;
        }
        
        NSArray *array = [NSArray array];
        if ([Helper stringBool:_task.class_list subStr:@"，"])
        {
            // 多个班级
            array =  [_task.class_list componentsSeparatedByString:@"，"];
            
            for (NSString *subStr  in array) {
                for (NSDictionary  *dic in self.allArr) {
                    
                    NSString *yUanStr = [NSString stringWithFormat:@"%@",dic[@"name"]];
                    if ([Helper stringBool:yUanStr subStr:subStr])
                    {
                        [self.seletedbanJiArr addObject:dic];
                    }
                    else
                    {

                    }
                    
                }
            }
            
        }
        else
        {
            // 单个班级
            for (NSDictionary  *dic in self.allArr) {
                
                NSString *yUanStr = [NSString stringWithFormat:@"%@",dic[@"name"]];
               // NNSLog(@"_task.class_list =%@=%@",_task.class_list,yUanStr);
                if ([Helper stringBool:yUanStr subStr:_task.class_list])
                {
                  //  NNSLog(@"包含单个");
                    [self.seletedbanJiArr addObject:dic];
                }
                else
                {
                   // NNSLog(@"不包含呀");
                }
                
            }
        }
        
        NNSLog(@"array=%@=",self.seletedbanJiArr); //结果是
        
    }
}





- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self getData];
}

#define placheder  @"请输入你的要求"
-(UITextView *)textView{
    if (!_textView) {
        _textView=[UITextView new];
        
        _textView.text = placheder;
        
        _textView.textColor = hui2Color;
        _textView.backgroundColor = [UIColor whiteColor];
        
        _textView.layer.borderColor = hui1Color.CGColor;
        
        _textView.layer.borderWidth = 1;
        
        _textView.delegate = self;
        
    }
    return _textView;
}



#pragma mark -----------------------textView 代理------------------------
-(void)textViewDidBeginEditing:(UITextView *)textView{
    if ([_textView.text isEqualToString:placheder]) {

        _textView.text=@"";
        _textView.textColor = [UIColor blackColor];
    }else{
      _textView.textColor = [UIColor blackColor];
    }

}

-(void)textViewDidEndEditing:(UITextView *)textView {
    
    if (textView.text.length == 0 || [textView.text isEqualToString: placheder])
    {
        _textView.text = placheder;
        
        _textView.textColor = hui2Color;
    }
    else
    {
        
        _textView.textColor = [UIColor blackColor];
    }
}

//正在改变
- (void)textViewDidChange:(UITextView *)textView

{
    //字数限制操作
    if (textView.text.length >= MaxTextLength)
    {
        textView.text = [textView.text substringToIndex:MaxTextLength];
        
    }
    
    //取消按钮点击权限，并显示提示文字
    if (textView.text.length == 0)
    {
        
    }
}

#pragma mark ----------------------- 打开班级 ------------------------
-(void)opeClass{
    
    [self.view endEditing:YES];
    SelectedBanJIVC *vc = [[SelectedBanJIVC alloc]init];
    vc.allArr = self.allArr;
    
    if (self.seletedbanJiArr.count > 0) {
        vc.rightLabelArray = self.seletedbanJiArr;
    }
    
    vc.selBlock = ^(NSMutableArray *arr) {
        
        NNSLog(@"%@",arr);
        
        self.seletedbanJiArr = arr;
        
        [self.collectionView reloadData];
        
    };
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0)
    {
        vc.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    }
    else
    {
        self.modalPresentationStyle=UIModalPresentationCurrentContext;
    }
    
    vc.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    
    [self.tabBarController presentViewController:vc animated:YES completion:nil];
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        
        UICollectionViewFlowLayout *layoyt = [[UICollectionViewFlowLayout alloc]init];
        
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 50, 50) collectionViewLayout:layoyt];
        
        _collectionView.backgroundColor = [UIColor clearColor];
        
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
        
        [_collectionView registerNib:[UINib nibWithNibName:ident bundle:nil] forCellWithReuseIdentifier:ident];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(opeClass)];
        
        _tap = tap;
        
        [_collectionView addGestureRecognizer:_tap];
        
//        _collectionView.backgroundView = self.backLabel;
        
        
    }
    return _collectionView;
}

-(UILabel *)backLabel{
    if (!_backLabel) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
        
        label.text = @"班级           请选择班级";
        label.textColor = hui3Color;
        _backLabel = label;
    }
    return _backLabel;
}

-(NSMutableArray *)allArr{
    if (!_allArr) {
        _allArr = [NSMutableArray array];
    }
    return _allArr;
}



-(NSMutableArray *)seletedbanJiArr{
    if (!_seletedbanJiArr) {
        _seletedbanJiArr = [NSMutableArray array];
    }
    return _seletedbanJiArr;
}

-(NSMutableArray *)banJiArr{
    if (!_banJiArr) {
        _banJiArr = [NSMutableArray array];
        
    }
    
    return _banJiArr;
}

#pragma mark ----------------------- 输入框验证 ------------------------
-(BOOL)yanZheng{
    if (_afield.text.length <= 0) {
         [MBProgressHUD showTextOnly:self.view message:@"请输入名称"delay:2];
        return NO;
    }
    
    if(_textView.text.length <= 0 || [_textView.text isEqualToString: placheder]){
         [MBProgressHUD showTextOnly:self.view message:@"请填写作业要求"delay:2];
        return NO;
    }
    if (_textView.text.length > MaxTextLength) {
         [MBProgressHUD showTextOnly:self.view message:[NSString stringWithFormat:@"字数只能%d",MaxTextLength] delay:2];
        return NO;
    }
    
    if (_seletedbanJiArr.count <= 0) {
       [MBProgressHUD showTextOnly:self.view message:@"请选择班级"delay:2];
        return NO;
    }
    
    if (_dfield.text.length <= 0) {
        [MBProgressHUD showTextOnly:self.view message:@"请选择时间"delay:2];
        return NO;
    }
    
    return YES;
    
}


#pragma mark ----------------------- 提交数据 -----------------------
-(void)tijiaoData {
    
    if ( [self yanZheng]==NO ) {
        return;
    }

    SGParameter *parameter  = [[SGParameter alloc] init];
    
    NSString *isFree = nil;
    if (self.isFree) {
        isFree = @"1"; // 赠送
    } else {
        isFree = @"0"; // 不赠送
    }
    
    NSString *classID = [NSString string];
    
    if (self.seletedbanJiArr.count <= 0) {
        return;
    }
    
    
    for (NSDictionary *dic  in self.seletedbanJiArr)
    {
        
        NSString *str = dic[@"id"];
        
        classID = [NSString stringWithFormat:@"%@%@,",classID,str];


    }
     classID = [classID substringToIndex:classID.length - 1];
    
    NSLog(@"classID = %@",classID);
    
    //13888889999
     NSString *lastUrl  = @"g=Client&m=Task&a=createTask";
    
    parameter.body = @{@"name":_afield.text,
                       @"detail":self.textView.text,
                       @"is_free":isFree,
                       @"class_ids":classID,
                       @"task_time":_dfield.text,
                       };
    
    if (_task) {
        NSLog(@"编辑");
        lastUrl  = @"g=Client&m=Task&a=updateTask";
        
        parameter.body = @{@"task_id":_task.id,//task_id
                           @"name":_afield.text,
                           @"detail":self.textView.text,
                           @"is_free":isFree,
                           @"class_ids":classID,
                           @"task_time":_dfield.text,
                           };

    }
    
    [SGHttpTool POST:[NSString stringWithFormat:@"%@%@",HTTPP,lastUrl] parameter:parameter sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject;
        
        NSString *str = dic[@"status"];
        
        if ([str integerValue] == 200) {
            
            [self updateUoppage];
 
            [self.navigationController popViewControllerAnimated:YES];
        }
        
        NNSLog(@"%@",dic);
        
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        
    }];

}

#pragma mark -----------------------  提交成功回调刷新  ------------------------
-(void)updateUoppage
{
    if (self.fresh)
    {

        _task.name       = _afield.text;
        _task.detail     =  _textView.text ;
        _task.work_time  =  _dfield.text;
        _task.is_free    = [NSString stringWithFormat:@"%zd",self.isFree];
        _task.class_list = [Helper stringFromArr:self.seletedbanJiArr key:@"name"];
//        NSLog(@"class_list = %@", _task.class_list);
        self.fresh(_task);

    }
    
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    if (self.seletedbanJiArr.count == 0) {
        _cfield.placeholder = @"请选择班级";
    }else{
        _cfield.placeholder = @"";
    }
    
    return self.seletedbanJiArr.count;
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NewTaskCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ident forIndexPath:indexPath];
    BTN_MSG_FUNC(cell.delButton, delSender:);
    
    cell.namelabel.text = self.seletedbanJiArr[indexPath.row][@"name"];
    
    cell.namelabel.textColor = [UIColor redColor];
    
    
    return cell;
}

- (void)delSender:(UIButton *)sender {
    
    
    NSIndexPath *myIndex=[self.collectionView indexPathForCell:(NewTaskCell *)[[sender superview] superview]];
    //如果按钮是加在cell上的contentView上
    NSLog(@"myIndex.section==%ld",myIndex.section);
    NSLog(@"myIndex.row==%ld",myIndex.row);

    
    NSLog(@"删除");
    
    [_seletedbanJiArr removeObjectAtIndex:myIndex.row];

    [_collectionView reloadData];
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"%zd",indexPath.row);
    
    
    [_seletedbanJiArr removeObjectAtIndex:indexPath.row];
    
    [_collectionView reloadData];

}

#define JianGe 10
#define GeShu 2

//定义每个UICollectionView 的大小
- ( CGSize )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:( NSIndexPath *)indexPath
{
    return CGSizeMake((collectionView.frame.size.width - JianGe*(GeShu+1)) / GeShu, 50);
}


//定义每个UICollectionView 的边距
- ( UIEdgeInsets )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:( NSInteger )section
{
    return UIEdgeInsetsMake ( JianGe , JianGe , JianGe , JianGe );
    
}

//设置水平间距 (同一行的cell的左右间距）
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return JianGe;
}

//垂直间距 (同一列cell上下间距)
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return JianGe;
}

-(void)layoutUI{
    
    //名称
    _afield = [UITextField new];
    _afield.placeholder = @"请输入任务名称";
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, SNRealValue(40))];
    label.text = @"名称";
    label.textColor = hui3Color;
    _afield.leftView = label;
    [_afield setLeftViewMode:(UITextFieldViewModeAlways)];
    
    [self.view addSubview:_afield];
    
    _afield.sd_layout
    .topSpaceToView(self.view,NAVIGATION_BAR_HEIGHT+20)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(HeightConfig(40));
    
    
    
    UIView *lina = [UIView new];
    lina.backgroundColor = hui1Color;
    [self.view addSubview:lina];
    lina.sd_layout
    .topSpaceToView(_afield, 5)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(1);
    
    // 要求
    _bfield = [UITextField new];
    UILabel *labelB = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, HeightConfig(40))];
    labelB.text = @"要求";
    labelB.textColor = hui3Color;
    _bfield.leftView = labelB;
    [_bfield setLeftViewMode:(UITextFieldViewModeAlways)];
     [self.view addSubview:_bfield];
//     _bfield.placeholder = @"请输入你的要求";
    
    _bfield.userInteractionEnabled = NO;
    
    
    
    _bfield.delegate = self;
    
    _bfield.sd_layout
    .topSpaceToView(lina, 0)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(HeightConfig(40));
    
    
    
    [self.view addSubview:self.textView];
    
    self.textView.sd_layout
    .topSpaceToView(_bfield, 0)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(HeightConfig(80));
    
    
    
    
    
    UIView *linb = [UIView new];
    linb.backgroundColor = hui1Color;
    [self.view addSubview:linb];
    linb.sd_layout
    .topSpaceToView(_textView, 10)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(1);
    
    
    // 班级
    [self.view addSubview:self.collectionView];
    
    
    
    self.collectionView.sd_layout
    .topSpaceToView(linb, 10)
    .leftSpaceToView(self.view, 70)
    .rightSpaceToView(self.view, 10)
    .heightIs(HeightConfig(80));

    
    _cfield = [UITextField new];
    UILabel *labelc = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, SNRealValue(40))];
    labelc.text = @"班级";
    labelc.textColor = hui3Color;
    _cfield.leftView = labelc;
    [_cfield setLeftViewMode:(UITextFieldViewModeAlways)];
    
    _cfield.placeholder = @"请选择班级";
    
    _cfield.userInteractionEnabled = NO;

    [self.view addSubview:_cfield];
    _cfield.sd_layout
    .topSpaceToView(linb, 10)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(HeightConfig(80));
    
    
    UIView *linc = [UIView new];
    linc.backgroundColor = hui1Color;
    [self.view addSubview:linc];
    
    linc.sd_layout
    .topSpaceToView(self.collectionView, 10)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(1);
    
    // 是否赠送
    UILabel *labeld = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, SNRealValue(40))];
    labeld.text = @"是否赠送";
    labeld.textColor = hui3Color;
    [self.view addSubview:labeld];
    
    labeld.sd_layout
    .topSpaceToView(linc, 10)
    .leftSpaceToView(self.view, 20)
    .widthIs(80)
    .heightIs(HeightConfig(40));
    
    UIView *lind = [UIView new];
    lind.backgroundColor = hui1Color;
    [self.view addSubview:lind];
    
    lind.sd_layout
    .topSpaceToView(labeld, 10)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(1);
    
    //添加男女选择
    NSMutableArray* buttons = [NSMutableArray arrayWithCapacity:2];
    CGRect btnRect = CGRectMake(ScreenWidth - 280, 0, 100, 40);
    
    RadioButton* btn = [[RadioButton alloc] initWithFrame:btnRect];
    [btn addTarget:self action:@selector(onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
    btnRect.origin.x += 10;
    [btn setTitle:@"否" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [btn setImage:[UIImage imageNamed:@"椭圆1"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"椭圆2"] forState:UIControlStateSelected];
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    [self.view addSubview:btn];

    btn.sd_layout
    .topSpaceToView(linc, 10)
    .leftSpaceToView(labeld,SNRealValue(20))
    .widthIs(WidthConfig(50))
    .heightIs(HeightConfig(40));
    
    [buttons addObject:btn];

    RadioButton* btn2 = [[RadioButton alloc] initWithFrame:btnRect];
    [btn2 addTarget:self action:@selector(onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
//    btnRect.origin.x += 60;
    [btn2 setTitle:@"是" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    btn2.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [btn2 setImage:[UIImage imageNamed:@"椭圆1"] forState:UIControlStateNormal];
    [btn2 setImage:[UIImage imageNamed:@"椭圆2"] forState:UIControlStateSelected];
    btn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    btn2.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    [self.view addSubview:btn2];

    btn2.sd_layout
    .topSpaceToView(linc, 10)
    .leftSpaceToView(btn, 10)
    .widthIs(WidthConfig(50))
    .heightIs(HeightConfig(40));
    
    [buttons addObject:btn2];
    [buttons[0] setGroupButtons:buttons]; // Setting buttons into the group
    [buttons[0] setSelected:YES];
    
    _buttons = buttons;
    
    // 时间选择
    _dfield = [UITextField new];
    UILabel *labele = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, SNRealValue(40))];
    labele.text = @"时间";
    labele.textColor = hui3Color;
    _dfield.leftView = labele;
    [_dfield setLeftViewMode:(UITextFieldViewModeAlways)];
    
    _dfield.placeholder = @"请选择时间";
    
    _dfield.userInteractionEnabled =NO;
    
//    [self.dfield setBackgroundColor: [UIColor blueColor]];
    
    [self.view addSubview:_dfield];
    
    _dfield.sd_layout
    .topSpaceToView( lind, 0)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(HeightConfig(40));
    
    UIButton *seltime = [UIButton buttonWithType:(UIButtonTypeCustom)];
    
    [seltime setBackgroundColor:[UIColor clearColor]];
    
    BTN_MSG_FUNC(seltime, openTime);
    
    [self.view addSubview:seltime];
    
    seltime.sd_layout
    .topSpaceToView( lind, 0)
    .leftSpaceToView(self.view, 20)
    .rightSpaceToView(self.view, 20)
    .heightIs(HeightConfig(40));
    
    
    // 确认按钮
    _button = [UIButton new];

    [_button setTitle:@"确认" forState:(UIControlStateNormal)];
    [_button setBackgroundColor:[UIColor redColor]];
    
    BTN_MSG_FUNC(_button, sendupdate:);
    [self.view addSubview:_button];
    
    _button.sd_layout
    .topSpaceToView(_dfield, 40)
    .rightSpaceToView(self.view, 50)
    .leftSpaceToView(self.view, 50)
    .heightIs(HeightConfig(40));
    
    
    
    
    
    


    
}

-(void)sendupdate:(UIButton *)sender{
    NSLog(@"提交");
    
    [self tijiaoData];
}

#pragma mark ----------------------- 选择时间 ------------------------
-(void)openTime{
    
    
    [self.view endEditing:YES];
    //年-月-日-时-分
    WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDayHourMinute CompleteBlock:^(NSDate *selectDate) {
    
        NSString *dateString = [selectDate stringWithFormat:@"yyyy-MM-dd HH:mm:ss"];

//        NSLog(@"选择的日期：%@",dateString);
//
//        NSString *time = [NSString stringWithFormat:@"%@:00",dateString];
        
        _dfield.text = dateString;
        

    }];
    datepicker.dateLabelColor = [UIColor redColor];//年-月-日-时-分 颜色
    datepicker.datePickerColor = [UIColor blackColor];//滚轮日期颜色
    datepicker.doneButtonColor = ZhuTiColor;//确定按钮的颜色
    [datepicker show];
}





-(void)textFieldDidBeginEditing:(UITextField *)textField{
    if (textField == _bfield) {
        NSLog(@"sdssfs");
        
        //        [_bfield resignFirstResponder];
    }
}





//选择男女的方法
-(void) onRadioButtonValueChanged:(RadioButton*)sender
{

    if(sender.selected) {
        
        NSLog(@"%@",sender.titleLabel.text);
        if ([sender.titleLabel.text isEqualToString:@"是"]) {;
            
            self.isFree = YES;
        }
        if ([sender.titleLabel.text isEqualToString:@"否"]) {
            
            self.isFree = NO;
        }
        
    }

}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
